import type { GlobalStore } from '@/types'

const useGlobalStore = defineStore('globalStore', {
  state: (): GlobalStore => ({
    isRefresh: false,
    navigationUrlData: new Set([]),
    isMenuRefresh: false,
    weather: {
      city: '',
      wea: '',
      wea_img: '',
      tem: '',
      tem_day: '',
      tem_night: '',
    },
  }),
  actions: {
    async refresh() {
      this.isRefresh = true
      await nextTick()
      this.isRefresh = false
    },
    async refreshMenu() {
      this.isMenuRefresh = true
      await nextTick()
      this.isMenuRefresh = false
    },
    async getWeather() {
      if (this.weather.city)
        return this.weather
      const res = await sysIntApi.getWeatherInfo()
      this.weather = res.data
      return res.data
    },
  },
})

export default useGlobalStore
